package com.task.sql.schedule.controller;

import com.task.sql.schedule.common.BaseController;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import com.task.sql.schedule.common.ApiResult;
import com.task.sql.schedule.common.PageResult;
import com.task.sql.schedule.domain.dto.SqlTaskGroupDTO;
import com.task.sql.schedule.domain.entity.SqlTaskGroup;
import com.task.sql.schedule.domain.qo.SqlTaskGroupQO;
import com.task.sql.schedule.domain.vo.SqlTaskGroupVO;
import com.task.sql.schedule.service.SqlTaskGroupService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 1.  前端控制器
 2.  3. @author donghai.liu
 4. @time 2024-09-10
 */
@Api(value = "接口", tags = {"相关接口"})
    @RestController
@RequestMapping("/sql-task-group")
public class SqlTaskGroupController extends BaseController {

    @Resource
    private SqlTaskGroupService service;

    @ApiOperation(value = "列表", notes = "列表", consumes = "application/json", produces = "application/json", httpMethod = "GET")
    @ApiResponses({@ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 50000, message = "service exception")
    })
    @GetMapping("/list")
    public PageResult<SqlTaskGroupVO> page(SqlTaskGroupQO qo) {
        return service.page(qo);
    }

    @ApiOperation(value = "获取信息", notes = "获取信息", consumes = "application/json", produces = "application/json", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true)
    })
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = SqlTaskGroup.class),
            @ApiResponse(code = 50000, message = "service exception")
    })
    @GetMapping("/get/{id}")
    public ApiResult<SqlTaskGroup> get(@PathVariable Long id) {
        SqlTaskGroup entity = service.getById(id);
        if(null == entity) {
            return ApiResult.error();
        }
        return ApiResult.success(entity);
    }

    @ApiOperation(value = "保存", notes = "保存", consumes = "application/json", produces = "application/json", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 50000, message = "service exception")
    })
    @PostMapping("/save")
    public ApiResult<Long> save(@RequestBody SqlTaskGroupDTO dto) {
        return service.save(dto);
    }

    @ApiOperation(value = "更新", notes = "更新", consumes = "application/json", produces = "application/json", httpMethod = "POST")
    @ApiResponses({@ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 50000, message = "service exception")
    })
    @PostMapping("/update")
    public ApiResult<Long> update(@RequestBody SqlTaskGroupDTO dto) {
        return service.update(dto);
    }

    @ApiOperation(value = "删除", notes = "删除", consumes = "application/json", produces = "application/json", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true)
    })
    @ApiResponses({@ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 50000, message = "service exception")
    })
    @DeleteMapping("/delete/{id}")
    public ApiResult<Void> delete(@PathVariable Long id) {
        service.removeById(id);
        return ApiResult.success();
    }
}
